package com.seveneight.baijiesteward.ui.first.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.BaseFragmentBack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by user1 on 2018/4/4.
 */

public class MyTeamFragment extends BaseFragmentBack implements View.OnClickListener {

    private String[] mTitles = {"直推", "间推"};
    private ImageView iv_back;
    private TextView tv_title;
    private List<BaseFragmentBack> fragmentList;
    private SlidingTabLayout tablayout;
    private ViewPager viewPager;

    public static MyTeamFragment newInstance() {
        Bundle args = new Bundle();
        MyTeamFragment fragment = new MyTeamFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected int getContentView() {
        return R.layout.fragment_myteam;
    }

    @Override
    protected void initView() {
        tv_title = findView(R.id.tv_title);
        tv_title.setText("我的团队");
        tablayout = findView(R.id.tablayout);
        viewPager = findView(R.id.viewpager);
        iv_back = findView(R.id.iv_back);
        fragmentList = new ArrayList<>();
        for (int i = 0; i < mTitles.length; i++) {
            fragmentList.add(new MyTeamListFragment(i+1));
        }
        FragmentManager childFragmentManager = getChildFragmentManager();
        MyPagerAdapter mAdapter = new MyPagerAdapter(childFragmentManager);
        viewPager.setAdapter(mAdapter);
        tablayout.setViewPager(viewPager);

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {
        iv_back.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                _mActivity.onBackPressed();
                break;
        }
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }
    }
}
